package com.wiscamp.ninechapters.problems.infrastructure.po.assessments;

import com.wiscamp.ninechapters.ddd.PersistenceObject;
import jakarta.persistence.*;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;

/**
 * 用户测评记录
 */
@Table(name = "user_assessment")
@Entity
@Data
public class UserAssessmentPO implements PersistenceObject {
    private static final long serialVersionUID = 1L;

    /**
     * 记录编号
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(insertable = false, name = "record_id", nullable = false)
    private long recordId;

    /**
     * 用户编号
     */
    @Column(name = "user_id", nullable = false)
    private long userId = 0;

    /**
     * 测评编号
     */
    @Column(name = "assessment_id", nullable = false)
    private long assessmentId = 0;

    /**
     * 习题集编号
     */
    @Column(name = "set_id", nullable = false)
    private long setId = 0;

    /**
     * 练习任务编号
     */
    @Column(name = "task_id", nullable = false)
    private long taskId = 0;

    /**
     * 模块名称
     */
    @Column(name = "module_name", nullable = false)
    private String moduleName = "";

    /**
     * 测评项名称
     */
    @Column(name = "program_name", nullable = false)
    private String programName = "";

    /**
     * 测评项序号
     */
    @Column(name = "program_index", nullable = false)
    private int programIndex = 0;

    /**
     * 测评方法
     */
    @Column(name = "assessment_method", nullable = false)
    private int assessmentMethod = 0;

    /**
     * 是否完成
     */
    @Column(name = "is_completed", nullable = false)
    private boolean completed = false;

    /**
     * 完成时间
     */
    @Column(name = "completed_time")
    private LocalDateTime completedTime;

    /**
     * 用户测评记录明细
     */
    @JoinColumn(name = "record_id", nullable = false, insertable = false, updatable = false)
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Collection<UserAssessmentDetailPO> details = new ArrayList<>();
}